package com.sixteen.theGreat.workbench.service.impl;

import com.sixteen.theGreat.commons.entity.ReturnObject;
import com.sixteen.theGreat.workbench.entity.Talk;
import com.sixteen.theGreat.workbench.mapper.TalkMapper;
import com.sixteen.theGreat.workbench.service.TalkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("talkService")
public class TalkServiceImpl implements TalkService {
    @Autowired
    private TalkMapper talkMapper;

    /**
     * 添加说说
     * @param talk
     * @return 返回结果封装到的实体类
     */
    @Override
    public Object addTalk(Talk talk) {
        int reg=talkMapper.insertTalk(talk);
        ReturnObject returnObject=new ReturnObject();
        if (reg > 0){
            returnObject.setCode(1);
        }else {
            returnObject.setCode(0);
            returnObject.setMessage("系统繁忙,请稍候...");
        }
        return returnObject;
    }

    /**
     * 根据userId 查询说说
     * @param userId
     * @return
     */
    @Override
    public List<Talk> queryTalkByUserId(String userId) {
        return talkMapper.selectTalkByUserId(userId);
    }

    /**
     * 根据talkId删除我的说说
     * @param talkId
     * @return
     */
    @Override
    public Object removeTalk(String[] talkId) {
        int reg= talkMapper.deleteTalk(talkId);
        ReturnObject returnObject=new ReturnObject();
        if (reg > 0) {
            returnObject.setCode(1);
        }else {
            returnObject.setCode(0);
            returnObject.setMessage("系统繁忙,请稍候...");
        }
        return returnObject;
    }

    /**
     * 查询好友说说
     * @param userId
     * @return
     */
    @Override
    public List<Talk> queryFriendTalkByHostId(String userId) {
        return talkMapper.selectFriendTalkByHostId(userId);
    }

    /**
     * 根据userId查询我的说说以及 我的好友的说说
     * @param userId
     * @return
     */
    @Override
    public List<Talk> queryAllTalkByUserId(String userId) {
        return talkMapper.selectAllTalkByUserId(userId);
    }


}
